import 'package:flutter/material.dart';
import 'package:flutter_base_study/pageview/view/image_view.dart';

class PageviewSwiper extends StatefulWidget {
  const PageviewSwiper({super.key});

  @override
  State<PageviewSwiper> createState() => _PageviewSwiperState();
}

class _PageviewSwiperState extends State<PageviewSwiper> {
  List<Widget> list = [];

  @override
  void initState() {
    super.initState();
    list = [
      ImageViewPage(
          url:
              'https://img0.baidu.com/it/u=2881522803,771576777&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500'),
      ImageViewPage(
          url:
              'https://img0.baidu.com/it/u=756784717,4222282671&fm=253&fmt=auto&app=138&f=JPEG?w=690&h=388'),
      ImageViewPage(
          url:
              'https://img0.baidu.com/it/u=3411979318,2994476395&fm=253&fmt=auto&app=138&f=JPG?w=681&h=418'),
    ];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('无线循环图，取余'),
      ),
      //PageViews实现 3张图
      // body: PageView(
      //   children: list,
      // ),

      //PageView.builder 无线循环的轮播图
      body: PageView.builder(
        itemCount: 10000,
        scrollDirection: Axis.horizontal,
        itemBuilder: (BuildContext context, int index) {
          //取余 0-1-2
          return list[index % list.length];
        },
      ),
    );
  }
}
